import { createApp } from 'vue'
import App from './App.vue'
import router from './router'

// 简单的事件总线实现
const eventBus = {
  events: {},
  on(event, callback) {
    if (!this.events[event]) {
      this.events[event] = [];
    }
    this.events[event].push(callback);
  },
  emit(event, data) {
    if (this.events[event]) {
      this.events[event].forEach(callback => callback(data));
    }
  },
  off(event, callback) {
    if (this.events[event]) {
      if (callback) {
        const index = this.events[event].indexOf(callback);
        if (index > -1) {
          this.events[event].splice(index, 1);
        }
      } else {
        this.events[event] = [];
      }
    }
  }
};

const app = createApp(App)

// 全局属性
app.config.globalProperties.$eventBus = eventBus;

app.use(router).mount('#app')